package com.qf.netty.handler.base;

import com.qf.netty.entity.Message;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * author Ken
 * create_time 2023/1/4
 */
public abstract class BaseMsgChannelHandler extends SimpleChannelInboundHandler<Message> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
        if (msg.getAction() == action()) {
            handler(ctx, msg);
        } else {
            ctx.fireChannelRead(msg);
        }
    }

    protected abstract int action();

    protected abstract void handler(ChannelHandlerContext ctx, Message msg);
}
